package com.ucpaas.sms.task.service;


import com.ucpaas.sms.task.entity.access.AccessChannelStatistics;
import com.ucpaas.sms.task.entity.access.CustomerStatTemp;
import com.ucpaas.sms.task.entity.access.SmsAccessSendStat;
import com.ucpaas.sms.task.entity.record.RecordConsumeStatistics;
import com.ucpaas.sms.task.enum4sms.AccessChannelStatisticsType;
import com.ucpaas.sms.task.exception.AccessChannelStatisticsException;
import com.ucpaas.sms.task.mapper.access.AccessChannelStatisticsMapper;
import com.ucpaas.sms.task.model.ResultVO;
import com.ucpaas.sms.task.model.TaskInfo;
import com.ucpaas.sms.task.statistic.AccessStatisticStrategy;
import com.ucpaas.sms.task.util.JacksonUtil;
import com.ucpaas.sms.task.util.JsonUtils;
import com.ucpaas.sms.task.util.StringUtil;
import com.ucpaas.sms.task.util.UcpaasDateUtils;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Map.Entry;

/**
 * @author huangwenjie
 * @title
 * @description 客户(用户)运营、运维报表统计
 * @date 2017-02-21
 */
@Service
public class ComplaintChannelStatisticsServiceImpl implements ComplaintChannelStatisticsService {
    private static final Logger LOGGER = LoggerFactory.getLogger("AccessChannelStatisticsService");

    @Autowired
    private AccessChannelStatisticsMapper accessChannelStatisticsMapper;

 /*   @Autowired
    private JsmsChannelOperationStatisticsService jsmsChannelOperationStatisticsService;

    @Autowired
    private JsmsClientOperationStatisticsService jsmsClientOperationStatisticsService;

    @Autowired
    private JsmsComplaintListService jsmsComplaintListService;*/






    @Autowired
    private RecordConsumeStatisticsService recordConsumeStatisticsService;

    @Autowired
    @Qualifier("deman1point5AccessStatistic")
    private AccessStatisticStrategy accessStatisticStrategy;
    @Resource(name = "access_transactionManager_new")
    private DataSourceTransactionManager txManager;


    @Transactional(value = "access")
    public ResultVO statistics(TaskInfo taskInfo) {
        statisticsAccess();
        statisticsRecord();
        return ResultVO.successDefault();
    }

    /*
    *通道侧统计
     */
    public void statisticsAccess(){
            /*JsmsChannelOperationStatistics model=new JsmsChannelOperationStatistics();
            Map params=new HashMap();
            List<AccessChannelStatistics> accessChannelStatisticss=accessChannelStatisticsMapper.queryAll(params);
            for(AccessChannelStatistics accessChannelStatistics:accessChannelStatisticss){
                model.setCostprice(accessChannelStatistics.getCostfee());
                model.setSubmitTotal(accessChannelStatistics.getSubmitsuccess()+accessChannelStatistics.getReportsuccess()+accessChannelStatistics.getSubretfail()+accessChannelStatistics.getReportfail());
                model.setReportsuccess(accessChannelStatistics.getReportsuccess());
                //低消条数
                model.setLowConsumeNumber(accessChannelStatistics.getSalefee());//低消条数
                //投诉系数
                model.setComplaintCoefficient(accessChannelStatistics.getSalefee());//投诉系数

                Map paramsComplain=new HashMap();
                paramsComplain.put("Id","");
                paramsComplain.put("date","");

            model.setComplaintNumber(jsmsComplaintListService.count(paramsComplain));

        }
        jsmsChannelOperationStatisticsService.update(model);*/
    }
    /*
     *用户统计
     */
    public void statisticsRecord(){
       /* JsmsClientOperationStatistics model=new JsmsClientOperationStatistics();
        Map params=new HashMap();
        List<JsmsClientOperationStatistics> jsmsClientOperationStatisticss=jsmsClientOperationStatisticsService.findList(params);
        for(JsmsClientOperationStatistics jsmsClientOperationStatistics:jsmsClientOperationStatisticss){

        }
        jsmsClientOperationStatisticsService.update(model);*/
    }
    public static Date printDate(Date date) {
        Date firstDate=new Date();
        try{
        SimpleDateFormat month = new SimpleDateFormat("yyyyMM");
        SimpleDateFormat day = new SimpleDateFormat("yyyyMMdd");
        String firstDay=month.format(date).toString()+"01";
        firstDate=day.parse(firstDay);
        }catch (Exception e){
            LOGGER.info("获取当月第一天失败：{}",e.toString());
        }
        return firstDate;
    }


}
